/**
 *
 */
package org.cloud.im.server.config;

import org.cloud.im.core.http.HttpConfig;
import org.cloud.im.core.utils.PropUtil;
import org.cloud.im.core.ws.WsConfig;

/**
 * @Author: w.weidong.lin@abite.com
 * @Description: TODO
 * @Date: create in 2021/10/19 14:39
 */
public class PropertyImServerConfigBuilder extends ImServerConfigBuilder<ImServerConfig,PropertyImServerConfigBuilder> {

	public PropertyImServerConfigBuilder(String file) {
		PropUtil.use(file);
	}

	@Override
	public PropertyImServerConfigBuilder configHttp(HttpConfig httpConfig)throws Exception{
		httpConfig.setBindPort(PropUtil.getInt("cloud.im.port"));
		//设置web访问路径;html/css/js等的根目录，支持classpath:，也支持绝对路径
		httpConfig.setPageRoot(PropUtil.get("cloud.im.http.page"));
		//不缓存资源;
		httpConfig.setMaxLiveTimeOfStaticRes(PropUtil.getInt("cloud.im.http.max.live.time"));
		//设置cloud-im mvc扫描目录;
		httpConfig.setScanPackages(PropUtil.get("cloud.im.http.scan.packages").split(","));
		return this;
	}

	@Override
	public PropertyImServerConfigBuilder configWs(WsConfig wsConfig)throws Exception{

		return this;
	}

	@Override
	protected PropertyImServerConfigBuilder getThis() {
		return this;
	}

	@Override
	public ImServerConfig build()throws Exception {
		super.build();
		return ImServerConfig.newBuilder()
				.bindIp(PropUtil.get("cloud.im.bind.ip"))
				.bindPort(PropUtil.getInt("cloud.im.port"))
				.heartbeatTimeout(PropUtil.getLong("cloud.im.heartbeat.timeout"))
				.isStore(PropUtil.get("cloud.im.store"))
				.httConfig(this.httpConfig)
				.wsConfig(this.wsConfig)
				.serverListener(this.serverListener)
				.isCluster(PropUtil.get("cloud.im.cluster")).build();
	}
}
